package com.mengniu.commerce.sync.api.factory;


import com.mengniu.commerce.sync.api.RemoteItemService;
import com.mengniu.commerce.sync.api.base.MnResult;
import com.mengniu.commerce.sync.api.domain.CreateItemModel;
import com.mengniu.commerce.sync.api.domain.ModifyItemModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 新增商品降级处理
 *
 * @author yz_sm
 */
@Component
public class RemoteItemFallbackFactory implements FallbackFactory<RemoteItemService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteItemFallbackFactory.class);

    @Override
    public RemoteItemService create(Throwable throwable)
    {
        log.error("数据同步服务调用失败:{}", throwable.getMessage());
        return new RemoteItemService()
        {
            @Override
            public MnResult createItem(List<CreateItemModel> list, String source)
            {
                return new MnResult("","新增商品失败:" + throwable.getMessage(),false);
            }

            @Override
            public MnResult modify(ModifyItemModel modifyItemModel, String source) {
                return new MnResult("","修改商品失败:" + throwable.getMessage(),false);
            }


        };
    }
}
